/**
 * author:Administrator
 * 
 */
package com.roc.web.action;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

/**
 * @author Administrator
 * @date:2013-11-9
 */
public class SysLogSearchCondition extends BaseSearchCondition {
	private String startDate;
	private String endDate;
	private String operators;
	private String[] operators_array;
	private String orgCode;
	private long merchantId;
	
	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getOrderPartOfHQL()
	 */
	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		return "order by t.dtCreate DESC";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getRowCountHQL()
	 */
	@Override
	protected String getRowCountHQL() {
		String sql="select count(*) from SysLog t where 1=1 ";
        if(Constance.isNotEmpty(orgCode)){

        	sql=sql+" and exists (select 1 from Operators o where o.oneagentid = "+orgCode+" and o.accountNo=t.operators)" ;
		}
		return sql;
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getSearchHQL()
	 */
	@Override
	protected String getSearchHQL() {
		// TODO Auto-generated method stub
		String sql="from SysLog t where 1=1 ";
        if(Constance.isNotEmpty(orgCode)){

		   sql=sql+" and exists (select 1 from Operators o where o.oneagentid = "+orgCode+" and o.accountNo=t.operators)" ;
		}
		return sql;
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getWhereHQLFieldBeanList()
	 */
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		// TODO Auto-generated method stub
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();

		 if(Constance.isNotEmpty(startDate)&&Constance.isNotEmpty(endDate)){
	        	Date date1=Constance.formateStartDate(startDate);
	        	Date date2 =Constance.formateEndDate(endDate);
	        	filedBeanList.add(new WhereHQLFieldBean("t.dtCreate",date1,
						">=", false));
	        	filedBeanList.add(new WhereHQLFieldBean("t.dtCreate",date2,
						"<=", false));
	     }
		 /*if(Constance.isNotEmpty(operators)){
			if(!"99".equals(operators)){
			 filedBeanList.add(new WhereHQLFieldBean("t.operators",operators,
						"=", false));
			 
			}else{
				filedBeanList.add(new WhereHQLFieldBean("t.operators",operators_array,
						"IN", false)); 
			 }
		 }*/
		return filedBeanList;
	}

	/**
	 * @return the startDate
	 */
	public String getStartDate() {
		return startDate;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	/**
	 * @return the endDate
	 */
	public String getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getOperators() {
		return operators;
	}

	public void setOperators(String operators) {
		this.operators = operators;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public long getMerchantId() {
		return merchantId;
	}

	public void setMerchantId(long merchantId) {
		this.merchantId = merchantId;
	}

	public String[] getOperators_array() {
		return operators_array;
	}

	public void setOperators_array(String[] operators_array) {
		this.operators_array = operators_array;
	}

}
